<template>
  <div class="indexBox">
    <ImitateNav v-model="currentNav"></ImitateNav>
    <a-card :bordered="false" :style="{marginTop:'20px'}">
      <!-- 搜索框 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="5" :sm="24">
              <a-form-item label>
                <a-input-search v-model="queryParam.memberId" placeholder="请输入角色名称/代码" />
              </a-form-item>
            </a-col>

            <a-col :md="4" :sm="24">
              <a-form-item label="是否启用">
                <a-select placeholder="--请选择类型--" allowClear @change="handleChange">
                  <a-select-option :value="1">启用</a-select-option>
                  <a-select-option :value="2">关闭</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :md="(!advanced && 10) || 24" :sm="24">
              <span>
                <a-button type="primary" icon="search" @click="loadDataRefresh()">查询</a-button>
              </span>
            </a-col>

            <a-col :md="(!advanced && 5) || 24" :sm="24" style="text-align: right;">
              <span>
                <a-button type="primary" icon="plus" @click="addTable()">新增</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <!-- 表单 -->
      <s-table
        ref="table"
        size="default"
        :bordered="false"
        :columns="columns"
        :data="loadData"
        :alert="false"
        showPagination="auto"
      >
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="edit(record)" style="margin:0 10px">
              <a-icon type="edit" />
              <span style="color:#999">编辑</span>
            </a>
            <a @click="power(record)" style="margin:0 10px">
              <a-icon type="share-alt" />
              <span style="color:#999">权限</span>
            </a>
            <a @click="dele(record)" style="margin:0 10px">
              <a-icon type="delete" />
              <span style="color:#999">删除</span>
            </a>
            <a @click="editAdmin(record)" style="margin:0 10px">
              <a-icon type="team" />
              <span style="color:#999">成员管理</span>
            </a>
            <a @click="goBoard()" style="margin:0 10px">
              <a-icon type="codepen" />
              <span style="color:#999">角色看板</span>
            </a>
          </template>
        </span>
      </s-table>
    </a-card>
    <!-- 弹框组件 -->
    <roleDataA ref="tabDialog"></roleDataA>
    <roleDataB ref="editTeam"></roleDataB>
    <roleDataC ref="rolePermission"></roleDataC>
  </div>
</template>

<script>
import moment from 'moment'
import ImitateNav from '@/components/_ImitateNav/ImitateNav'
import { STable, Ellipsis } from '@/components'
import roleDataA from '@/views/role/modules/roleData-a'
import roleDataB from '@/views/role/modules/roleData-b'
import roleDataC from '@/views/role/modules/roleData-c'
import { putAction, deleteAction, getAction, dele } from '@/api/manage'
const columns = [
  {
    title: '序号',
    align: 'center',
    width: '50px',
    dataIndex: 'id',
  },
  {
    title: '角色代码',
    dataIndex: 'createBy',
    width: '130px',
    align: 'center',
  },
  {
    title: '角色名',
    dataIndex: 'name',
    width: '130px',
    align: 'center',
  },
  {
    title: '描述',
    dataIndex: 'description',
    ellipsis: true,
    width: '200px',
    align: 'center',
  },
  {
    title: '是否启用',
    dataIndex: 'amount',
    align: 'center',
    width: '60px',
  },
  {
    title: '创建时间',
    align: 'center',
    dataIndex: 'createTime',
    width: '150px',
  },

  {
    title: '操作',
    dataIndex: 'action',
    width: '300px',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]

export default {
  name: 'TableList',
  components: {
    STable,
    Ellipsis,
    ImitateNav,
    roleDataA,
    roleDataB,
    roleDataC,
  },
  data() {
    this.columns = columns
    return {
      currentNav: '角色管理',
      visible: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      dataFile: [],
      // 查询参数
      queryParam: { keywords: '', certifiedBusinessStatus: '', startTime: '', endTime: '', memberId: '' },
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({ sort: 'createTime,desc' }, parameter, this.queryParam)
        console.log('loadData request parameters:', requestParameters)
        return getAction('/api/listRoles', requestParameters).then((res) => {
          return {
            ...requestParameters,
            totalCount: res.result.totalElements,
            totalPage: 10,
            data: res.result.content,
          }
        })
      },
      selectedRowKeys: [],
      selectedRows: [],
    }
  },

  computed: {
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
      }
    },
  },

  methods: {
    handleChange(value) {
      // this.queryParam.clientType = value
      console.log(this.queryParam.clientType)
      this.loadDataRefresh()
    },

    edit(record) {
      this.$refs.tabDialog.show(record)
      console.log(record)
    },

    goBoard() {
      this.$router.push({ path: '/a/roleBoard' })
    },
    editAdmin(record) {
      this.$refs.editTeam.show(record)
      console.log(record)
    },
    loadDataRefresh() {
      this.$refs.table.refresh() // refresh() 不传参默认值 false 不刷新到分页第一页
    },
    power(record) {
      this.$refs.rolePermission.show(record)
      this.dataFile = record
      localStorage.setItem('dataFales', JSON.stringify(record))
      // this.$router.push({
      //   path: '/sym/manage/rolePermission',
      //   query: {
      //     id: record.id,
      //     menu: record.menu,
      //     name: record.name,
      //   },
      //})
    },
    dele(record) {
      let self = this
      console.log(record)
      this.$confirm({
        title: '确认删除',
        content: '是否删除选中数据?',
        onOk() {
          deleteAction('/api/businessAuthApply', Object.assign({ id: record.id })).then((res) => {
            if (res.code == 0) {
              self.$refs.table.refresh()
              self.$message.success(res.msg)
            } else {
              self.$message.warning('删除失败')
            }
          })
        },
      })
    },
    addTable() {
      console.log(this.$refs.tabDialog)
      this.$refs.table.refresh()
      this.$refs.tabDialog.visible = true
      // this.$refs.tabDialog.title = '新增'
    },
  },
}
</script>
